﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Vds2465Telegrams
{
    [TestClass]
    public class UserData_20_State_Test
    {
        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test01_Equals_NoReportType()
        {
        	const eAddressExtension_1_InputOutput addressExtension1InputOutput = eAddressExtension_1_InputOutput.Input;
			UserData_20_State userData = new UserData_20_State(0x01, 0x18, 0x03, addressExtension1InputOutput, null);

            {
                // completely different type - NOT equal
                object dummyObject = new object();
                Assert.IsFalse(userData.Equals(dummyObject));
            }

            {
                // different derived type
                UserData userData2Compare = new UserData_01_Priority(0x77);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

			{
				// compare with disruption variant with the same address byte value
				UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, eDisruptionCode.SecondaryTransmissionError, userData.AddressAddOn, userData.TheReportType);
				Assert.IsFalse(userData.Equals(userData2Compare));
			}

            {
                // same object - equal
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, userData.TheReportType);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // different Device value - NOT equal
                UserData_20_State userData2Compare = new UserData_20_State
					((byte)(userData.Device + 1), userData.Address, userData.AddressAddOn, addressExtension1InputOutput, userData.TheReportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different Address value - NOT equal
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, (byte)(userData.Address + 10), userData.AddressAddOn, addressExtension1InputOutput, userData.TheReportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different AddressAddOn value - NOT equal
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, userData.Address, (byte)(userData.AddressAddOn + 5), addressExtension1InputOutput, userData.TheReportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // different AddressExtension value - NOT equal
                eAddressExtension_1_InputOutput addressExtension = eAddressExtension_1_InputOutput.Output;
				if (addressExtension1InputOutput == eAddressExtension_1_InputOutput.Output)
                {
                    addressExtension = eAddressExtension_1_InputOutput.Input;
                }
                UserData_20_State userData2Compare = new UserData_20_State
                    (userData.Device, userData.Address, userData.AddressAddOn, addressExtension, userData.TheReportType);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test02_Equals_ReportType()
        {
			const eAddressExtension_1_InputOutput addressExtension1InputOutput = eAddressExtension_1_InputOutput.Output;
            ReportType_Fire reportTypeFire = new ReportType_Fire(true, eReportSubType_Fire.ExtinguishingSystem);
			UserData_20_State userData = new UserData_20_State(0x01, 0x02, 0x03, addressExtension1InputOutput, reportTypeFire);

            {
                // same object - equal
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, userData.TheReportType);
                Assert.IsTrue(userData.Equals(userData2Compare));
            }

            {
                // same properties but no ReportType
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, null);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same properties but different ReportType
                ReportType_General reportTypeGeneral = new ReportType_General(false, eReportSubType_General.Revision);
                UserData_20_State userData2Compare = new UserData_20_State
					(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, reportTypeGeneral);
                Assert.IsFalse(userData.Equals(userData2Compare));
            }

            {
                // same properties with same ReportType Sub type but different on off flag
                ReportType_Base reportTypeRet = userData.TheReportType;
                ReportType_Fire reportTypeRetFire = reportTypeRet as ReportType_Fire;
                if (reportTypeFire != null)
                {
                    ReportType_Fire reportTypeFire2Compare = new ReportType_Fire(!reportTypeRetFire.OnOffFlag, reportTypeRetFire.ReportSubType);

                    UserData_20_State userData2Compare = new UserData_20_State
						(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, reportTypeFire2Compare);
                    Assert.IsFalse(userData.Equals(userData2Compare));
                }
            }

            {
                // same properties with same ReportType Sub type but different ...
                ReportType_Base reportTypeRet = userData.TheReportType;
                ReportType_Fire reportTypeRetFire = reportTypeRet as ReportType_Fire;
                if (reportTypeFire != null)
                {
                    eReportSubType_Fire eReportSubTypeFire = eReportSubType_Fire.General;
                    if (reportTypeRetFire.ReportSubType == eReportSubType_Fire.General)
                    {
                        eReportSubTypeFire = eReportSubType_Fire.Automatic;
                    }
                    ReportType_Fire reportTypeFire2Compare = new ReportType_Fire(reportTypeRetFire.OnOffFlag, eReportSubTypeFire);

                    UserData_20_State userData2Compare = new UserData_20_State
						(userData.Device, userData.Address, userData.AddressAddOn, addressExtension1InputOutput, reportTypeFire2Compare);
                    Assert.IsFalse(userData.Equals(userData2Compare));
                }
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test03_GetHashCode()
        {
            {
                UserData_20_State userData = new UserData_20_State(0x01, 0x02, 0x03, eAddressExtension_1_InputOutput.Input, null);
                int hashCode = userData.GetHashCode();
            }

            {
                ReportType_Fire reportTypeFire = new ReportType_Fire(true, eReportSubType_Fire.ExtinguishingSystem);
                UserData_20_State userData = new UserData_20_State(0x01, 0x02, 0x03, eAddressExtension_1_InputOutput.Input, reportTypeFire);
                int hashCode = userData.GetHashCode();
            }
        }

        [TestMethod]
        [Owner("Frank Eppink")]
        public void Test04_ToString()
        {
            {
                UserData_20_State userData = new UserData_20_State(0x01, 0x02, 0x03, eAddressExtension_1_InputOutput.Input, null);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }

            {
                ReportType_General reportTypeGeneral = new ReportType_General(false, eReportSubType_General.Revision);
                UserData_20_State userData = new UserData_20_State(0x01, 0x02, 0x03, eAddressExtension_1_InputOutput.Input, reportTypeGeneral);
                string stringResult = userData.ToString();
                Assert.IsNotNull(stringResult);
            }
        }
    }
}
